package com.felix.stream;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.stream.Collectors.*;

/**
 * DownStreamCollectors
 *
 * @author xjh
 * @version 1.0
 * @date 2019-03-21
 */
public class DownStreamCollectors {
    public static void main(String[] args) {
        List<City> list = Lists.newArrayList(new City("1", "10"), new City("1", "100"), new City("2", "20"));
        Map<String, Set<String>> collect = list.stream().collect(groupingBy(City::getName, mapping(City::getAlias, toSet())));
        System.out.println(collect);
    }

}

@Data
@AllArgsConstructor
@NoArgsConstructor
class City {
    private String name;
    private String alias;
}
